using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Roslyn.Compilers.Common;

namespace NUMP4CS
{
    public static class  RoslynExtension
    {
        public static bool HasAsBase(this INamedTypeSymbol rootType, INamedTypeSymbol baseType)
        {
            bool result = false;
            if (rootType != null)
            {
                result = (rootType.Equals(baseType));
                if (result==false && rootType.BaseType != null)
                {
                    result = rootType.BaseType.HasAsBase(baseType);
                }

            }
            return result;
        }

        public static IEnumerable<object>ToModelAccessibility(this ISymbol _this)
        {
            List<object> result = new List<object>();
            switch (_this.DeclaredAccessibility)
            {
                case CommonAccessibility.Private:
                    result.Add(Accessibility.@private);
                    break;
                case CommonAccessibility.Public:
                    result.Add(Accessibility.@public);
                    break;

                case CommonAccessibility.Protected:
                    result.Add(Accessibility.@protected);
                    break;
                case CommonAccessibility.Internal:
                    result.Add(Accessibility.@internal);
                    break;
                case CommonAccessibility.ProtectedAndInternal:
                case CommonAccessibility.ProtectedOrInternal:
                    result.Add(Accessibility.@protected);
                    result.Add(Accessibility.@internal);
                    break;

                default:
                    break;
            }
            if (_this.IsAbstract) { 
                result.Add(Accessibility.@abstract);
            }
            if (_this.IsStatic)
            {
                result.Add(Accessibility.@static);
            }
            if (_this.IsSealed) 
            {
                result.Add(Accessibility.@sealed);
            }
            if (_this.IsAbstract)
            {
                result.Add(Accessibility.@abstract);
            }

            return result;
        }
    }
}
